package com.inventory.api.signUpReq;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Created by lihu on 2018/2/2.
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class StockCheckSignUpReq {
    @NotNull(message = "参数错误")
    private String id;

    @NotNull(message = "参数错误")
    private String storeId;

    private String operatorId;

    /**
     * 操作人名称
     */
    private String operatorName;

    /**
     * 种类
     */
    private int kind = 0;
    /**
     * 盘盈总个数量
     */
    private int singleProfit;

    /**
     * 盘盈总件数量
     */
    private int wholeProfit;

    /**
     * 盘亏总个数量
     */
    private int singleLosses;


    /**
     * 盘亏总件数量
     */
    private int wholeLosses;

    /**
     * 备注
     */
    private String notes;

    private List<CheckProduct> products;


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class CheckProduct {

        @NotNull(message = "参数有误")
        private String productId;

        @NotNull(message = "参数有误")
        private String productName;

        @NotNull(message = "参数有误")
        private int stockPrice;

        @NotNull(message = "参数有误")
        private int stockQuantityRatio = 1;

        /**
         * 实际总个数量
         */
        @NotNull(message = "参数有误")
        private int checkSingleQty;

        /**
         * 实际总件数
         */
        @NotNull(message = "参数有误")
        private int checkWholeQty;

        /**
         * 应有个数
         */
        @NotNull(message = "参数有误")
        private int accurateSingleQty;

        /**
         * 应有件数
         */
        @NotNull(message = "参数有误")
        private int accurateWholeQty;


        /**
         * 备注
         */
        private String notes;

        /**
         * 获取实际库存数
         *
         * @return
         */
        public int getCheckTotalQty() {
            return (checkWholeQty * stockQuantityRatio + checkSingleQty);
        }

        /**
         * 获取应有数量
         *
         * @return
         */
        public int getAccurateTotalQty() {
            return accurateWholeQty * stockQuantityRatio + accurateSingleQty;
        }

        /**
         * 校验出入库方式 true为一种方式 false （有入库也有出库）
         *
         * @return
         */
        public boolean checkSockType() {
            if ((checkWholeQty < accurateWholeQty && checkSingleQty < accurateSingleQty) ||
                    (checkWholeQty > accurateWholeQty && checkSingleQty > accurateSingleQty ||
                            (checkWholeQty == accurateWholeQty && checkSingleQty != accurateSingleQty) ||
                            (checkWholeQty != accurateWholeQty && checkSingleQty == accurateSingleQty))) {
                return true;
            } else {
                return false;
            }
        }

        /**
         * 校验是否保存库存记录
         *
         * @return
         */
        public boolean checkSock() {
            if (checkWholeQty == accurateWholeQty && checkSingleQty == accurateSingleQty) {
                return true;
            }

            return false;
        }

    }
}
